<template>
	<page-meta :page-style="'overflow:' + (filterPopShow ? 'hidden' : 'visible')"></page-meta>
	<view class="content">
		<u-navbar :safeAreaInsetTop="true" :placeholder="true">
			<view class="u-nav-slot" slot="left">
			</view>
			<view class="fx_1" slot="center">
				<view class="fx fx_nw aic w100" v-if="appType == base.USER_TYPE">
					<view class="width_25 height_25 br_20 nav_logo">

						<image class="width_25 height_25" :src="dealInfo.logo" mode="aspectFit"></image>
					</view>
					<!-- <image class="width_72 height_25" :src="platformInfo.logo" mode="aspectFit"></image> -->
					<text class="ml_4 fx_1 fe">{{ dealInfo.showName }}</text>
				</view>
				<template v-else>
					<view class="fc">变色龙</view>
				</template>
			</view>
		</u-navbar>
		<!-- <view @click="scancode">扫码</view> -->
		<template v-if="permission">
			<u-sticky :offsetTop="topHeight">
				<view class="search-bar-box">
					<navigator :url="noLogin?'/pages/account/pages/login':'/pages/goods/pages/search'"
						hover-class="none" id="search-bar">
						<uni-search-bar radius="16" placeholder="输入商品分类、名称" readonly cancelButton="none"
							:Serachbutton='1'>
						</uni-search-bar>
					</navigator>
				</view>
			</u-sticky>
			<u-swiper :list="banners" height="440rpx" circular indicator
				:indicatorStyle="{ 'text-align': 'center', 'bottom': '60rpx' }" @click="handleClickSwiper">
			</u-swiper>
			<view class="pr plr_12">

				<view class="cell cellbar" v-if="noticeList.length">
					<NoticeBar :duration="3000" bgColor="#fff" :text="noticeList" direction="column" fontSize="250" />
				</view>


				<view class="fx fx_w mt_6 br_8 ptb_8 pl_11 pr_12 bc_fff gridr_4 gridc_22 "
					v-if="Object.keys(bannerDir).length">
					<view class="width_48 fx_sh aic mb_15" v-for="item,index in bannerDir" :key="index"
						@click="handlePermis(item, index)">
						<image class="width_48 height_48" :src="item.imgUrl" mode="aspectFit"></image>
						<view class="fz_12 fc fe width_48">
							{{ item.title }}
						</view>
					</view>
				</view>


				<!--活动专栏-->
				<view class="ActivityColumn fx" v-if="allData&&!noLogin">
					<view class="ActivityColumn-item active" style="position: relative;"
						@click="handleClick(bannerDir[1])">
						<view>
							<image class="width_68 height_17" src="@/static/images/index-ActivityColumn.png"
								mode="aspectFit">
							</image>
							<CountDown :time="seckillCountdown" color="#ffd5cc"
								style="position:absolute; right: 12rpx; top: 12rpx;"
								v-if="allData.seckillProductList&&seckillCountdown" @finish="handleSeckillFinish" />

							<view class="activ-timechang" v-if="allData.seckillProductList">
								{{allData.seckillBeginTime}} 场
							</view>

							<view class="fx ActivityColumn_left">
								<template v-if="allData.seckillProductList">
									<view class="fx_1 ActivityColumn_left_item" style="margin-right: 8rpx;">
										<image class="width_68 height_68 br_8"
											:src="allData.seckillProductList[0].coverImageUrl" mode="aspectFit">
										</image>
										<view style="color: #FE0000; font-size: 24rpx;">
											￥{{allData.seckillProductList[0].seckillPrice}}</view>
										<view
											style="color: #BBBBBB; font-size: 18rpx; text-decoration-line:line-through;">
											￥{{allData.seckillProductList[0].originalPrice}}</view>
									</view>

									<view class="fx_1 ActivityColumn_left_item" style="margin-left: 8rpx;">
										<image class="width_68 height_68 br_8"
											:src="allData.seckillProductList[1].coverImageUrl" mode="aspectFit">
										</image>
										<view style="color: #FE0000; font-size: 24rpx;"
											v-if="allData.seckillProductList[1]">
											￥{{allData.seckillProductList[1].seckillPrice}}</view>
										<view
											style="color: #BBBBBB; font-size: 18rpx;  text-decoration-line:line-through;"
											v-if="allData.seckillProductList[1]">
											￥{{allData.seckillProductList[1].originalPrice}}</view>
									</view>
								</template>
								<template v-else>
									<view class="fx_1 fc">
										<image class="width_100 height_98 ib" src="@/static/images/home_act_empty.png"
											mode=""></image>
										<view class="fc fz_12 pr" style="color: #c8c8c8;top: -40rpx;">
											活动筹备中，敬请期待
										</view>
									</view>
								</template>
							</view>
						</view>
					</view>
					<view class="fx_1 fx_sh fx fx_col gap-10">
						<view class="ActivityColumn-item-right w100" :style="{
							height: '184rpx',
						}" @click="handleClick(bannerDir[2])">
							<view class="ActivityColumn-item-title">
								拼优惠<text>一起拼都便宜</text>
							</view>
							<view class="fx" v-if="allData.groupProductList && allData.groupProductList.length">
								<image class="width_56 height_56 mr_8 br_8"
									:src="allData.groupProductList[0].coverImageUrl" mode="aspectFit"></image>
								<view class="fx_1">
									<text
										class="col-333 fz_12 mb_24 textconl">{{allData.groupProductList[0].productName}}</text>
									<text style="color:#999; margin-top: 40rpx; display: block;"
										class=" fz_12">已拼{{allData.groupProductList[0].sales || 0}}件</text>
								</view>

							</view>
							<view class="fx_1 fc" v-else>
								<image class="width_60 height_58 ib" src="@/static/images/home_act_empty.png" mode="">
								</image>
								<view class="fc fz_12 pr" style="color: #c8c8c8;top: -40rpx;">
									活动筹备中，敬请期待
								</view>
							</view>
						</view>
						<view class="ActivityColumn-item-right  w100" style="height: 184rpx;">
							<view class="ActivityColumn-item-title">
								爆品抢购<text>国产好货补贴</text>
							</view>
							<view class="fx" v-if="allData.scrambleProductList && allData.scrambleProductList.length">
								<image class="width_50 height_50 mr_8 br_8"
									:src="allData.scrambleProductList[0].coverImageUrl" mode="aspectFit"></image>
								<view class="fx_1">
									<text
										class="col-333 fz_12 mb_12 textconl">{{allData.scrambleProductList[0].productName}}</text>
									<view class="qiang-acitvity fx">
										<view class="fx_1" style="margin-right: 38rpx;">
											<text class="fz_8">补贴价</text><br />
											{{allData.scrambleProductList[0].salePrice}}
										</view>
										<view class="fx_1" @click="handleClick(bannerDir[3])">
											立即<br />
											抢购
										</view>
									</view>
								</view>

							</view>
							<view class="fx_1 fc" v-else>
								<image class="width_60 height_58 ib" src="@/static/images/home_act_empty.png" mode="">
								</image>
								<view class="fc fz_12 pr" style="color: #c8c8c8;top: -40rpx;">
									活动筹备中，敬请期待
								</view>
							</view>

						</view>
					</view>
				</view>

				<view class="cell" v-if="vipList.length">
					<view class="fx aic jcc pr">
						<view class="fb fz_16 public-index-title">
							会员连锁店专区
						</view>
						<navigator class="pa" style="right: -4rpx;" hover-class="none" url="/pages/goods/pages/vip">
							<view class="fx aic jce fc_999">
								更多
								<u-icon name="arrow-right" color="#999" size="24rpx"></u-icon>
							</view>
						</navigator>
					</view>
					<view class="mt_18 pr_12 fx fx_nw flow_x scroll_h">
						<view class="list_item" v-for="item, index in vipList" :key="index">
							<GoodsCard :data="item" toDetail>
							</GoodsCard>
						</view>
					</view>
				</view>


				<view class="cell" v-if="allData.bargainirgProductList&&allData.bargainirgProductList.length&&!noLogin">
					<view class="fx aic jcc">
						<view class="fb fz_16 public-index-title">
							砍价活动
						</view>
						<!-- <view class="fx aic jce fc_999" @click="handleClick(bannerDir[4])">
							更多
							<u-icon name="arrow-right" color="#999" size="24rpx"></u-icon>
						</view> -->
					</view>
					<view class="mt_12 fx fx_w jcb">
						<GoodsCard type="vertical-card4" v-for="item, index in allData.bargainirgProductList.slice(0,4)"
							:data="item" :key="index" goodsType="3">
						</GoodsCard>
					</view>
				</view>
				<view class="mt_8 ptb_12 pl_12 br_8 bc_fff" v-if="typeList && typeList.length">
					<view class="fx aic jcb">
						<view class="fb fz_16">
							好物推荐
						</view>
						<view class="width_220 tabs-wrap">
							<u-tabs :current="type" :list="typeList" keyName="typeName" lineColor="#FE5A1C"
								itemStyle="font-size:24rpx;padding: 0 16rpx 12rpx;" inactiveStyle="color: #999999"
								lineWidth="48rpx" lineHeight="10rpx" @change="handleType"></u-tabs>
						</view>
					</view>
					<view class="mt_6 pr_12 fx fx_nw flow_x scroll_h">
						<view class="list_item" v-for="item, index in goodsList" :key="index">
							<GoodsCard :data="item" toDetail>
							</GoodsCard>
						</view>
					</view>
					<view class="ptb_16 fc" v-if="goodsLoading">
						<u-loadmore status="loading" />
					</view>
				</view>
				<view class="mt_8 ptb_12 pl_12 br_8 brand_wrap bc_fff"
					v-if="allData.brandPavilionList && allData.brandPavilionList.length">
					<view class="fx aic jcb">
						<view class="fb">
							品牌上新
						</view>
						<navigator class="fx aic jce fc_999 pr_12" hover-class="none"
							:url="noLogin?'/pages/account/pages/login':'/pages/goods/pages/brand'">
							更多
							<u-icon name="arrow-right" color="#999" size="24rpx"></u-icon>
						</navigator>
					</view>
					<view class="mt_18 fx fx_nw flow_x scroll_h">
						<navigator hover-class="none"
							:url="noLogin?'/pages/account/pages/login':`/pages/goods/pages/search?brandId=${item.id}&brandName=${item.brandName}`"
							class="list_item flow_h fx_sh" v-for="item, index in allData.brandPavilionList"
							:key="index">
							<view class="pr width_243 height_115 flow_h fx aic jcc">
								<image class="pa t_0 l_0 w100 h100" :src="getStaticUrl(item.brandImageUrl)"
									mode="aspectFill"></image>
								<image class="maxh_72 maxw_160 br_8" style="opacity: 0.8;"
									:src="getStaticUrl(item.brandLogoUrl)" mode="aspectFit"></image>
							</view>
							<view class="fc fe fz_12 width_243 fe mt_12 fc_999">
								<text
									class="fc_333 mr_8">{{item.brandName||''}}</text>{{ item.brandIntroduction || '' }}
							</view>
						</navigator>
					</view>
				</view>
				<u-sticky :offsetTop="tabsTop">
					<view class="tabs_wrap">
						<u-tabs :current="type" :list="cateList" keyName="typeName" lineColor="#F08519"
							itemStyle="font-size:30rpx;padding: 10rpx 16rpx; " activeStyle="color: #F08519"
							inactiveStyle="color: #999999" lineWidth="48rpx" lineHeight="2rpx"
							@change="handleGoodsType"></u-tabs>
					</view>
				</u-sticky>
				<view class="mt_8 bc_fff br_8 flow_h" style="min-height:80vh;">
					<zero-filter-bar ref="zeroFilterBar" :dataList="filterList" :hasFilter="hasFilter"
						:needSticky="false" :extraBtn="false" selectColor="#FE5A1C" @filter='handleFilterItem' />
					<view class="plr_12 pb_12 fx fx_w jcb">
						<view v-for="item, index in dataList" :key="index">
							<CusImage width="320rpx" height="500rpx" radius="8rpx" :src="item.url" mode="aspectFit"
								v-if="item.banner" @click.native="handleClickBanner(item)" />
							<GoodsCard :showIcon="true" :data="item" v-else>
							</GoodsCard>
						</view>
					</view>
					<view class="ptb_38" v-if="!loading && !dataList.length">
						<Empty type="search" size="86" />
					</view>
					<view class="ptb_16" v-if="dataList.length">
						<u-loadmore :status="loadingStatus" />
					</view>
				</view>
			</view>
		</template>
		<template v-else>
			<NoPermission :requestCount="requestCount" :ossUrl="ossUrl" :basicUnserInfo="basicUnserInfo" />
		</template>
		<u-back-top :scroll-top="scrollTop" bottom="208" right="36" :zIndex="1000" :customStyle="{'z-index':1000}"
			v-if="showTop">
			<image class="width_48 height_48 box_shadow br50" :src="ossUrl + '/back_top.png'" mode="aspectFit">
			</image>
		</u-back-top>
		<PopupFilter :navTop="true" :data="filterParams" :originData="filterOriginParams" :show="filterPopShow"
			@confirm="handleConfirmFilter" @close="filterPopShow = false" />
		<PopupPreview :visible.sync="popupPreviewVisible" :list="popupBanners"></PopupPreview>
		<PopupCoupon :visible.sync="popupCouponVisible" :list="couponList"></PopupCoupon>

	</view>
</template>

<script>
	import CusImage from '@/components/Image'
	import GoodsCard from '@/components/goods/GoodsCard.vue'
	import CountDown from '@/components/CountDown'
	import PopupFilter from '@/components/goods/PopupFilter.vue'
	import NoticeBar from '@/components/notice-bar/notice-bar/notice-bar.vue'
	import api from '@/service/config/api'
	import Empty from '@/components/Empty'
	import NoPermission from "@/components/noPermission.vue"
	import PopupPreview from '@/components/PopupPreview'
	import PopupCoupon from '@/components/PopupCoupon.vue'
	import {
		mapState,
		mapMutations,
		mapGetters
	} from 'vuex'
	import backTopMixin from '@/mixins/back_top.js'
	import bannerMixin from '@/mixins/banner'
	import dataMixin from '@/mixins/data.js'
	import filterMixin from '@/mixins/filter.js'
	import permissionMixin from '@/mixins/permission.js'
	import stickyTopMixin from '@/mixins/sticky_top.js'
	import {
		getStaticUrl
	} from '@/utils/index.js'
	const ossUrl = "https://bsl-app-images.oss-cn-beijing.aliyuncs.com/wechat-app/images"
	const bannerDirTemplate = {
		1: {
			title: '秒杀',
			imgUrl: `${ossUrl}/index_banner_1.png`,
			url: '/pages/goods/pages/seckill',
			permis: true
		},
		2: {
			title: '拼团',
			imgUrl: `${ossUrl}/index_banner_2.png`,
			url: '/pages/goods/pages/group',
			permis: true
		},
		3: {
			title: '抢购',
			imgUrl: `${ossUrl}/index_banner_4.png`,
			url: '/pages/goods/pages/rush_purchase',
			permis: true
		},
		4: {
			title: '砍价',
			imgUrl: `${ossUrl}/index_banner_3.png`,
			url: '/pages/goods/pages/bargain',
			permis: true
		},
		5: {
			title: '红包',
			imgUrl: `${ossUrl}/index_banner_5.png`,
			url: '/pages/activities/pages/redpacket',
			permis: true
		},
		6: {
			title: '品牌馆',
			imgUrl: `${ossUrl}/index_banner_6.png`,
			url: '/pages/goods/pages/brand',
			permis: true
		},
		7: {
			title: '任务',
			imgUrl: `${ossUrl}/index_banner_10.png`,
			url: '/pages/person/pages/mission',
			permis: true
		},
		8: {
			title: '积分商城',
			imgUrl: `${ossUrl}/index_banner_7.png`,
			url: '/pages/goods/pages/integral',
			permis: true
		},
		9: {
			title: '邀请好友',
			imgUrl: `${ossUrl}/index_banner_8.png`,
			url: '/pages/common/pages/invite',
			permis: true
		},
		10: {
			title: '领优惠券',
			imgUrl: `${ossUrl}/index_banner_9.png`,
			url: '/pages/common/pages/coupon',
			permis: true
		},
		11: {
			title: '全部分类',
			imgUrl: `${ossUrl}/index_banner_10.png`,
			url: "/pages/index/categery",
			type: '2'
		},
		12: {
			title: '大转盘',
			imgUrl: `${ossUrl}/index_banner_6.png`,
			url: '/pages/goods/heBigWheel/heBigWheel',
			permis: true
		}

	}
	const menuDir = {
		2: 2,
		3: 1,
		4: 3,
		5: 4,
		6: 5
	}

	export default {
		mixins: [bannerMixin, backTopMixin, dataMixin, permissionMixin, stickyTopMixin, filterMixin],
		components: {
			GoodsCard,
			CountDown,
			PopupFilter,
			Empty,
			NoticeBar,
			NoPermission,
			PopupPreview,
			PopupCoupon,
			CusImage
		},
		data() {
			return {
				base: this.$base,
				bannerDir: {},
				title: 'Hello',
				dataInfo: {
					banner: []
				},
				filterList: [{
						id: 0,
						name: '综合',
					},
					{
						id: 1,
						name: '销量',
						sort: true
					},
					{
						id: 2,
						name: '价格',
						sort: true
					},
					{
						id: 3,
						name: '筛选',
						filter: true,
					},
				], // 筛选项
				filterPopShow: false, // 筛选开关
				scrollTop: 0,
				showTop: false,
				recommendCateList: [], // 好物推荐分类
				bannerId: 1, // banner位置
				userInfo: this.$storage.getItem('basicUnserInfo') || {},
				allData: {}, // 数据集合
				listUrl: '/goods/api/product/productList',
				dataList: [], // 商品列表
				params: {
					orderBy: 0,
					...this.$store.state.userInfo.customerId ? {
						customerId: this.$store.state.userInfo.customerId
					} : {},
					appletType: this.$store.state.appType === this.$base.ADMIN_TYPE ? 0 : 1,
				},
				typeList: [], // 好物推荐分类
				type: 0,
				goodsList: [], // 好物推荐列表
				goodsLoading: false,
				seckillCountdown: 0, // 秒杀倒计时
				noticeList: [], // 滚动消息
				vipList: [], // 会员连锁列表
				popupBanners: [], // 首页弹窗
				popupPreviewVisible: false,
				refeshData: false,
				couponList: [],
				popupCouponVisible: false,
				cateList: [],
				productBanners: [], // 商品列表banner
				size: 30,
				initTenentInfo: false, // 初始化店铺信息
			}
		},
		computed: {
			...mapState(['userType', 'appType', 'platformInfo', 'dealInfo']),
			...mapGetters(['noLogin']),
			// 是否筛选
			hasFilter() {
				const {
					brandSelect,
					styleSelect,
					materialSelect,
					minPrice,
					maxPrice
				} = this.filterParams
				return !!brandSelect || !!styleSelect || !!materialSelect || !!minPrice || !!maxPrice
			},
			getStaticUrl() {
				return (src) => getStaticUrl(src)
			},
			checkToken() {
				return !!this.$storage.getItem('token')
			},
			seckillProductListLength() {
				return this.Data?.seckillProductList?.length && true
			},
			tabsTop() {
				return this.topHeight + (52 / (uni.upx2px(52) / 52))
			},
			salePrice() {
				return (data) => {
					if (this.noLogin) {
						return data.originalPrice || 0
					}
					const goodsType = this.$utils.goodsTypeDir(data.goodsType)
					const price = this.$store.state.appType === this.$base.USER_TYPE ? (data.salePrice || 0) : (data
						.wholesalePrice ||
						data.salePrice || 0)
					if (goodsType == 2) {
						return data.seckillPrice || price || 0
					}
					if (goodsType == 3) {
						return data.bargainirgMinPrice || price || 0
					}
					if (goodsType == 5) {
						return data.groupPrice || price || 0
					}
					return price || 0
				}
			},
		},
		watch: {
			initTenentInfo(newVal) {
				if(newVal) {
					this.getFirstData()
					if (this.checkToken && this.appType === this.$base.USER_TYPE) {
						this.getNews()
					}
				}
			}
		},
		onLoad(options) {
			this.getTopHeight()
			console.log("获取加载", options)
			uni.login({
				success(res) {
					console.log("获取code")
					console.log(res)
				}
			})
			if (options.shareId) {
				this.$storage.setItem('shareId', options.shareId)
			}
			this.getTenentInfo()
		},
		onShow() {
			console.log("appType == base.USER_TYPE")
			console.log(this.dealInfo)
			console.log(this.appType)
			console.log(this.$base.USER_TYPE)
			this.showTop = true
			this.$utils.getSetting()
			if(this.initTenentInfo) {
				this.getFirstData()
				if (this.checkToken && this.appType === this.$base.USER_TYPE) {
					this.getNews()
				}
			}
		},
		onHide() {
			this.showTop = false
		},
		methods: {
			getTenentInfo() {
				api.post('/user/api/auth/getSocialTenantId', {
					type: "APP-MINI",
					platformId: uni.getAccountInfoSync().miniProgram.appId
				}).then(res => {
					uni.setStorageSync("tenantId", res.data.id)
					uni.setStorageSync("platformInfo", res.data)
					this.$store.commit('setFunctionRange', res.data.id)
				}).finally(()=>{
					setTimeout(()=>{
						this.initTenentInfo = true
						this.getFilterData()
						this.getTypeData()
						this.getCateList()
						if (this.$store.state.userInfo.customerId) {
							this.$set(this.params, 'customerId', this.$store.state.userInfo.customerId)
						}
						console.log('this.$store.state.userInfo', this.$store.state.userInfo)
						this.$set(this.params, 'userType', this.$store.state.userInfo.identityType || 1)
						// this.getData(true)
						Promise.all([...['', '', ''].map((item, index) => this.getProductBanner(index + 13)), this.getData(true)])
						this.getBannerTopData()
						if (this.checkToken && !this.$storage.getItem('showCoupon')) {
							this.getCoupon()
						}
					},100)
				})
			},
			scancode() {
				uni.scanCode({
					success(res) {
						const scene = decodeURIComponent("scene=id%3D1780521538162356225")
						console.log("扫码结果")
						console.log(res)
						console.log(scene)
						const codeArr = scene.split("=")
						console.log(codeArr)
						uni.navigateTo({
							url: '/' + res.path
						})
					}
				})
			},
			getProductBanner(index) {
				return new Promise((resolve, reject) => {
					api.get('/base/api/tAppletBanner/inner/queryByShowLocation', {
						showLocation: index,
						tenantId: uni.getStorageSync("tenantId")
					}, {
						noHideLoading: true
					}).then(res => {
						if (res.data && res.data.length) {
							this.productBanners.push({
								...res.data[0],
								url: (this.$utils.getStaticUrl(res.data[0].images))
							})
						}
						resolve()
					}).catch(() => {
						resolve()
					})
				})
			},
			getData(refresh = false) {
				return new Promise(resolve => {
					this.isSearching = true
					if (refresh) {
						this.current = 1
						this.total = 1
						this.end = false
						// this.$utils.loading()
					} else {
						this.loading = true
					}
					if (this.listUrl) {
						api[this.httpMethod](this.listUrl, {
							current: this.current,
							size: this.size,
							...this.params ? this.params : {}
						}, {
							noHideLoading: this.noHideLoading
						}).then(res => {
							if (refresh) {
								let sum = 0
								const adPushList = new Array(this.productBanners.length).fill('').map(
									item => {
										sum += Math.floor(Math.random() * 3) + 6
										return sum
									})
								if (res.data && res.data.records) {
									adPushList.forEach((item, index) => {
										if (res.data.records[item]) {
											res.data.records.splice(item, 0, {
												banner: true,
												...this.productBanners[index]
											})
										}
									})
								}
							}
							this.dataList = refresh ? (res.data.records || []) : [...this.dataList, ...(res
								.data
								.records || [])];
							if (res.data.pages <= this.current) {
								this.end = true
							}
							this.getDataNext && this.getDataNext()
						}).finally(() => {
							this.loading = false
							this.initLoading = false
							resolve()
						})
					}
				})
			},
			handleClickBanner(item) {
				if (this.$store.state.appType == this.$base.USER_TYPE) {
					if (!this.$storage.getItem('token')) {
						this.$utils.modalRedirectToLogin()
						return
					}
				} else {
					if (!this.$storage.getItem('token')) {
						this.$utils.modalRedirectToLogin()
						return
					} else if ((this.userType == 3 && this.basicUnserInfo.dealerAuditStatus == 2 && !this
							.basicUnserInfo
							.paySetMeal)) {
						this.$utils.showModal({
							title: '提示',
							confirmText: '去购买',
							content: '您还未购买套餐'
						}).then(() => {
							setTimeout(() => {
								uni.reLaunch({
									url: '/pages/common/pages/product'
								})
							}, 1500)
						})
						return
					}
				}
				let url = ''
				switch (item.jumpMethod) {
					case '1':
						url = `/pages/common/pages/richtext?id=${item.id}&banner=true`
						break;
					case '2':
						url = '/pages/goods/pages/seckill'
						break;
					case '3':
						url = '/pages/goods/pages/rush_purchase'
						break;
					case '4':
						url = '/pages/goods/pages/bargain'
						break;
					case '5':
						url = '/pages/goods/pages/group'
						break;
					case '6':
						url = '/pages/goods/pages/detail?id=' + item.productId
						break;
					case '7':
						url = '/pages/goods/pages/search?brandId=' + item.productId
						break;
					case '9':
						url = '/pages/goods/pages/integral'
						break;
					default:
						break;
				}
				if (url) {
					uni.navigateTo({
						url
					})
				}
			},
			getBannerTopData() {
				api.get(this.checkToken ? '/base/api/tAppletBanner/queryByShowLocation' :
					'/base/api/tAppletBanner/inner/queryByShowLocation', {
						showLocation: 2,
						tenantId: uni.getStorageSync("tenantId")
					}, {
						noHideLoading: true,
						noToast: true
					}).then(res => {
					if (res.data && res.data.length) {
						this.popupBanners = res.data.map(item => ({
							...item,
							url: (this.$utils.getStaticUrl(item.images))
						}))
						this.popupPreviewVisible = true;
					}
				})
			},
			getFirstData() {
				// this.$utils.loading()
				let p = Promise.all([this.getAllData(), this.getMenuData(), this
					.getBannerData(), (this
						.appType == this.$base.USER_TYPE ? this.getVipList() : Promise.resolve()
					), (this
						.appType == this.$base.USER_TYPE ? this.getDealerInfo() : Promise
						.resolve())
				])
				p.finally(() => {
					uni.hideLoading()
				})
			},
			getDealerInfo() {
				return new Promise(resolve => {
					api.get('/user/api/user/getDealerInfo', {}, {
						noHideLoading: true
					}).then(res => {
						// uni.setStorageSync("platformInfo", res.data)
						// this.$store.commit('setPlatformInfo', res.data)
						uni.setStorageSync("dealInfo", res.data)
						this.$store.commit('setDealInfo', res.data)
					}).finally(() => {
						resolve()
					})
				})
			},
			// 获取金刚区菜单
			getMenuData() {
				return new Promise(resolve => {
					api.post('/user/api/auth/getSocialTenantId', {
						type: 'APP-MINI',
						platformId: uni.getAccountInfoSync().miniProgram.appId
					}, {
						noHideLoading: true,
						noHeaders: true
					}).then(res => {
						console.log('返回请求体', res)
						let bannerDir = JSON.parse(JSON.stringify(bannerDirTemplate))
						if (res.data.tenantType == 0) {
							console.log("我进来了")
							delete bannerDir[7]
							delete bannerDir[12]
							this.bannerDir = bannerDir
							resolve()
						} else {
							api.post('/user/api/user/getFunctionModule', {}, {
								noHideLoading: true
							}).then(res => {
								if (res.data && res.data.length) {
									this.filterMenu(res.data, resolve)
								} else {
									this.filterMenu([], resolve)
								}
							}).catch(() => {
								this.filterMenu([], resolve)
							})
						}
					}).catch(err => {
						this.filterMenu([], resolve)
					})
				})
			},
			// 获取首页数据集合
			getAllData() {
				return new Promise(resolve => {
					api.get('/goods/api/product/getFirstPageList', {
						userType: this.$store.state.userInfo.identityType || 1,
						functionRange: this.$store.state.functionRange,
						...this.$store.state.userInfo.customerId ? {
							customerId: this.$store.state.userInfo.customerId
						} : {},
						appletType: this.$store.state.appType === this.$base.ADMIN_TYPE ? 0 : 1,

					}, {
						noHideLoading: true
					}).then(res => {
						this.allData = res.data

						if (res.data.seckillEndTime) {


							this.seckillCountdown = this.$utils.getFullTime(res.data.seckillEndTime) -
								new Date().getTime()
						}
					}).finally(() => {
						resolve()
					})
				})
			},
			handleSeckillFinish() {
				if (!this.refeshData)
					this.getFilterData()
				this.refeshData = true
			},
			// 获取筛选信息
			getFilterData() {
				// this.$utils.loading()
				let p = Promise.all([this.getBrandList(), this.getStyleList(), this.getMaterialList()])
				p.finally(() => {
					uni.hideLoading()
				})
			},
			// 获取商品品牌
			getBrandList() {
				return new Promise(resolve => {
					api.get('/goods/api/product/getBrandList', {
						functionRange: this.$store.state.functionRange
					}, {
						noHideLoading: true
					}).then(res => {
						this.$set(this.filterParams, 'brandList', res.data)
						this.$set(this.filterOriginParams, 'brandList', res.data)
					}).finally(() => {
						resolve()
					})
				})
			},
			// 获取商品风格
			getStyleList() {
				return new Promise(resolve => {
					api.get('/goods/api/product/getStyleList', {}, {
						noHideLoading: true
					}).then(res => {
						this.$set(this.filterParams, 'styleList', res.data)
						this.$set(this.filterOriginParams, 'styleList', res.data)
					}).finally(() => {
						resolve()
					})
				})
			},
			// 获取商品材质
			getMaterialList() {
				return new Promise(resolve => {
					api.get('/goods/api/product/getMaterialList', {}, {
						noHideLoading: true
					}).then(res => {
						this.$set(this.filterParams, 'materialList', res.data)
						this.$set(this.filterOriginParams, 'materialList', res.data)
					}).finally(() => {
						resolve()
					})
				})
			},
			// 获取好物推荐分类
			getTypeData() {
				return new Promise(resolve => {
					api.get('/goods/api/product/getGoodTypeList', {}, {
						noHideLoading: true,
						noToast: true
					}).then(res => {
						this.typeList = res.data || []
						if (this.typeList.length) {
							this.getGoodsList(this.typeList[0].id)
						}
					}).catch(() => {
						this.getGoodsList()
					})
				})
			},
			getCateList() {
				api.get('/goods/api/product/getTypeList', {
					id: 0
				}, {
					noHideLoading: true
				}).then(res => {
					if (res.data && res.data.length) {
						res.data.unshift({
							typeName: '精选'
						})
					}
					this.cateList = res.data
				})
			},
			// 获取好物推荐列表
			getGoodsList(id) {
				this.goodsList = []
				this.goodsLoading = true
				api.get('/goods/api/product/goodProductList', {
					size: 10,
					current: 1,
					userType: this.$store.state.userInfo.identityType || 1,
					...this.$store.state.userInfo.customerId ? {
						customerId: this.$store.state.userInfo.customerId
					} : {},
					orderBy: 0,
					appletType: this.$store.state.appType === this.$base.ADMIN_TYPE ? 0 : 1,
					...id ? {
						productTypeId: id
					} : {},
				}, {
					noHideLoading: true
				}).then(res => {
					this.goodsList = res.data && res.data.records ? res.data
						.records : []
				}).finally(() => {
					this.goodsLoading = false
				})
			},
			// 获取会员商品
			getVipList() {
				return new Promise(resolve => {
					api.get('/goods/api/product/membershipChainProductList', {
						userType: this.$store.state.userInfo.identityType || 1,
						current: 1,
						size: 10,
						orderBy: 0,
						...this.$store.state.userInfo.customerId ? {
							customerId: this.$store.state.userInfo.customerId
						} : {},
						appletType: this.$store.state.appType === this.$base.ADMIN_TYPE ? 0 : 1,
					}, {
						noHideLoading: true,
					}).then(res => {
						this.vipList = (res.data && res.data.records) ? res.data
							.records : []
					}).finally(() => {
						resolve()
					})
				})
			},
			// 获取会员商品
			getUserInfo() {
				return new Promise(resolve => {
					api.get('/user/api/auth/userInfo', {}, {
						noHideLoading: true,
					}).then(res => {
						if (!res.data.paySetMeal) {

						}
					}).finally(() => {
						resolve()
					})
				})
			},
			// 获取滚动消息
			getNews() {
				api.get('/user/api/myScoring/item100', {}, {
					noHideLoading: true,
				}).then(res => {
					this.noticeList = res.data
				})
			},
			handleClick(item) {
				console.log(item)
				// if (this.noLogin) {
				// 	return this.$utils.modalRedirectToLogin()
				// }
				if (item.title == '红包') {
					if(!this.$storage.getItem('token')) {
						this.$utils.showToast('红包不定期开发，请稍后再试');
						return;
					}
					this.$utils.loading()
					api.get('/marketing/applet/api/user/red_packet/on_off_state', {

					}).then(res => {
						if (res.data && res.data.state == "on") {
							if (res.data.nowRedPacket) {
								uni.navigateTo({
									url: item.url
								})
							} else {
								this.$utils.showToast('红包活动还未开始')
							}

						} else {
							this.$utils.showToast('红包不定期开发，请稍后再试')
						}
					})
				} else if (item.title == '大转盘') {
					if(this.noLogin) {
						this.$utils.showToast('大转盘不定期开放，请稍后再试')
						return;
					}
					let shujs = uni.getStorageSync('tenantId')

					return new Promise(resolve => {

						api.get('/goods/api/bigWheel/getBigWheelApplet2', {
							functionRange: shujs
						}, ).then(res => {
							// console.log(res)
							if (!res.data.id) {
								this.$utils.showToast('大转盘不定期开放，请稍后再试')
							} else {
								uni.navigateTo({
									url: item.url
								})
							}
						}).finally(() => {

						})
					})
				} else {
					if (item.type == 2) {
						uni.switchTab({
							url: item.url
						})
					} else {
						uni.navigateTo({
							url: item.url
						})
					}
				}
			},
			setItem() {
				uni.showToast({
					title: '存储成功'
				})
			},
			getItme() {
				this.add()
			},
			// 选择筛选项
			handleFilterItem(index, desc, item) {
				switch (index) {
					case 0:
						this.params.orderBy = 0
						this.getData(true);
						break;
					case 1:
						this.params.orderBy = desc ? 1 : 2
						this.getData(true);
						break;
					case 2:
						this.params.orderBy = desc ? 3 : 4
						this.getData(true);
						break;
					case 3:
						this.filterPopShow = !this.filterPopShow
						break;
					default:
						break;
				}
			},
			// 切换好物推荐tab
			handleType({
				id
			}) {
				if (id) {
					this.getGoodsList(id)
				}
			},
			handleGoodsType({
				id
			}) {
				if (id) {
					this.$set(this.params, 'productTypeId', id)
				} else {
					this.$delete(this.params, 'productTypeId')
				}
				this.getData(true)
			},
			handleGoodsDetail(item) {
				if (item.id) {
					uni.navigateTo({
						url: `/pages/goods/pages/detail?id=${item.id}&goodsType=2`
					})
				}
			},
			// 筛选金刚区菜单
			filterMenu(arr, resolve) {
				let index = 0
				let bannerDir = JSON.parse(JSON.stringify(bannerDirTemplate))
				delete bannerDir[6]
				delete bannerDir[11] //临时删去全部分类
				const arr1 = [2, 3, 4, 5, 6]
				arr1.map(item => {
					if (!arr.includes(item)) {
						index++
						delete bannerDir[menuDir[item]]
					}
				})
				if (index > 0) {
					// const cateMenu = bannerDir[11]

					api.get('/goods/api/product/getTypeList', {
						id: 0
					}, {
						noHideLoading: true
					}).then(res => {


						if (res.data && res.data.length) {

							res.data.slice(0, index).map((item1, index1) => {
								bannerDir[13 + index1] = {
									title: item1.typeName || '',
									imgUrl: this.getStaticUrl(item1.typeIconUrl),
									url: `/pages/goods/pages/search?typeId=${item1.id}&typeName=${item1.typeName}`
								}

								this.bannerDir = bannerDir

								// this.$set(this.bannerDir, 11 + index1, {
								// 	title: item1.typeName || '',
								// 	imgUrl: this.getStaticUrl(item1.typeIconUrl),
								// 	url: `/pages/goods/pages/search?typeId=${item1.id}&typeName=${item1.typeName}`
								// })
							})



							resolve()
						} else {
							resolve()
						}
					}).catch(() => {
						resolve()
					})
				} else {

					this.bannerDir = bannerDir

					resolve()
				}
			},
			getCoupon() {
				api.get('/marketing/applet/api/user/discount_coupon/list/unclaimed', {
					dealerId: this.$store.state.functionRange,
				}, {
					noHideLoading: true,
					noToast: true
				}).then(res => {
					this.couponList = res.data
					if (res.data.length) {
						this.popupCouponVisible = true;
						this.$storage.setItem('showCoupon', true)
					}
				}).finally(() => {})
			},
			handlePermis(item, index) {
				const noPermis = ['1','2','3','4','5','6','8','11']
				if(noPermis.includes(index)) {
					this.handleClick(item)
					return
				}
				item.permis ? this.$utils.permis(false).then(() => this.handleClick(item)) : this.handleClick(item)
			}
		}
	}
</script>

<style lang="scss">
	page {
		padding-bottom: 0;
	}

	page {
		padding-bottom: 0;
	}
</style>

<style lang="scss" scoped>
	/deep/.time__custom__item {
		color: #f00;
	}

	/deep/.u-navbar--fixed {
		z-index: 10076 !important;
	}

	.nav_logo {
		overflow: hidden;
		margin-left: 24rpx;
	}

	.textconl {

		width: 160rpx;
		margin: auto 0;
		/*设置为弹性盒子*/
		display: -webkit-box;
		/* 表示几行后超出隐藏 */
		-webkit-line-clamp: 1;
		/* 超出隐藏 */
		overflow: hidden;
		/*超出显示为省略号*/
		text-overflow: ellipsis;
		-webkit-box-orient: vertical;
		/*强制英文单词自动换行*/
		word-break: break-all;

	}

	.ActivityColumn {
		background: #F93914;
		border-radius: 16rpx;
		margin-top: 16rpx;
		// margin-bottom: 48rpx;
		padding: 8rpx;
		box-sizing: border-box;

		.gap-10 {
			gap: 10rpx;
		}

		.ActivityColumn-item {
			background: #FFFAF9;
			border-radius: 12rpx;
			box-sizing: border-box;

			&.active {
				width: 352rpx;
				background: linear-gradient(180deg, #FFE0DA 0%, #FFFFFF 31%);
				margin-right: 8rpx;
				padding: 16rpx;
			}

			.activ-timechang {
				width: 112rpx;
				height: 42rpx;
				background: #F93914;
				border-radius: 8rpx;
				text-align: center;
				line-height: 42rpx;
				color: #fff;
				margin-top: 10rpx;
				font-size: 24rpx;
				position: relative;

				&::after {
					content: '';
					position: absolute;
					width: 12rpx;
					height: 12rpx;
					background: #F93914;
					left: 50%;
					bottom: -4rpx;
					transform: rotate(45deg);
				}
			}

			.ActivityColumn_left {
				margin-top: 16rpx;
			}

			.ActivityColumn_left_item {
				text-align: center;

				image {
					margin-bottom: 16rpx;
				}
			}
		}

		.ActivityColumn-item-right {
			background: #FFFAF9;
			border-radius: 12rpx;
			padding: 12rpx 16rpx 8rpx 16rpx;
			box-sizing: border-box;

			.ActivityColumn-item-title {
				color: #333;
				font-size: 32rpx;
				font-weight: bold;
				margin-bottom: 12rpx;

				text {
					color: #999;
					margin-left: 8rpx;
					font-size: 24rpx;
					font-weight: normal;
				}

			}

			.qiang-acitvity {
				background: url(../../static/images/qianggou.png) no-repeat center;
				background-size: cover;
				height: 64rpx;
				width: 180rpx;
				color: #fff;
				font-size: 24rpx;
				line-height: 32rpx;
				padding-left: 24rpx;
			}
		}

	}

	.tabs_wrap {
		background: #F6F6F6;
	}

	.content {
		.search-bar-box {
			padding: 24rpx;
			background: #F6F6F6;
		}

		/deep/.uni-searchbar {
			padding: 0 !important;
			border: 2rpx solid #F08519;
			margin: 0;
			border-radius: 666rpx;
			height: 64rpx;
		}

		/deep/.uni-searchbar__box {
			justify-content: flex-start !important;
			height: auto;

		}

		.cell {
			border-radius: 16rpx;
			padding: 28rpx 16rpx;

			margin-top: 16rpx;

			&.cellbar {
				background: #fff;
			}
		}


		.list_item+.list_item {
			margin-left: 12rpx;
		}

		.brand_wrap {
			.list_item {}
		}
	}
</style>